<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
</head>
<body>
    <div id="app">
        <h2>用户登录</h2>
        <input type="text" v-model="username">
        <br><br>
        <input type="password" v-model="password">
        <br>
        <div v-if="message" style="color: red">{{message}}</div>
        <br>
        <button @click="login()">登录</button>
    </div>
    <script type="application/javascript" src="vue.js"></script>
    <script type="application/javascript" src="axios.js"></script>
    <script>
        let app = new Vue({
            el: "#app",
            data: {
                username: '',
                password: '',
                message: '',
            },
            methods: {
                login: function () {
                    app.message = '';
                    axios.post(
                        "api/user/login",
                        {
                            username: app.username,
                            password: app.password,
                        }
                    ).then(function (resp) {
                        let body = resp.data;
                        if(body.ok){
                            //登录成功，跳转到首页
                            window.location.href = "index.html";
                        }else{
                            app.message = body.message;
                        }
                    })
                }
            }
        });
    </script>
</body>
</html>